<?php

namespace App\Containers\AppSection\Authentication\Tasks;

use App\Ship\Parents\Tasks\Task;
use Laravel\Passport\RefreshTokenRepository;
use Laravel\Passport\TokenRepository;

class RevokeTokensTask extends Task
{
    public function run($userId)
    {
        $tokens = app(TokenRepository::class)->forUser($userId)->pluck('id')->toArray();
        foreach ($tokens as $tokenId) {
            app(TokenRepository::class)->revokeAccessToken($tokenId);
            app(RefreshTokenRepository::class)->revokeRefreshTokensByAccessTokenId($tokenId);
        }
    }
}
